//
//  CZD_OtherDetailTimeLineCell.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2020/9/27.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "CZD_OtherDetailTimeLineCell.h"

@interface CZD_OtherDetailTimeLineCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) CZD_OtherDetailTimeLineView *view1;
@property (nonatomic, strong) CZD_OtherDetailTimeLineView *view2;
@property (nonatomic, strong) CZD_OtherDetailTimeLineView *view3;
@property (nonatomic, strong) CZD_OtherDetailTimeLineView *view4;
@property (nonatomic, strong) CZD_OtherDetailTimeLineView *view5;
@property (nonatomic, strong) CZD_OtherDetailTimeLineView *view6;
@property (nonatomic, strong) CZD_OtherDetailTimeLineView *view7;
@property (nonatomic, strong) CZD_OtherDetailTimeLineView *view8;
@property (nonatomic, strong) CZD_OtherDetailTimeLineView *view9;
@property (nonatomic, strong) CZD_OtherDetailTimeLineView *view10;
@property (nonatomic, strong) CZD_OtherDetailTimeLineView *view11;
@property (nonatomic, strong) CZD_OtherDetailTimeLineView *view12;

@end

@implementation CZD_OtherDetailTimeLineCell

+ (instancetype)CZD_OtherDetailTimeLineCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"CZD_OtherDetailTimeLineCell";
    CZD_OtherDetailTimeLineCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[CZD_OtherDetailTimeLineCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [[UIView alloc] initWithFrame:CGRectMake(15, 10, ScreenW - 30, 390)];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        self.height = self.bgView.nim_bottom;
        
        self.view1 = [[CZD_OtherDetailTimeLineView alloc] initWithFrame:CGRectMake(15, 15, self.bgView.nim_width - 30, 30)];
        [self.bgView addSubview:self.view1];
        
        self.view2 = [[CZD_OtherDetailTimeLineView alloc] initWithFrame:CGRectMake(self.view1.nim_left, self.view1.nim_bottom, self.view1.nim_width, self.view1.nim_height)];
        [self.bgView addSubview:self.view2];
        
        self.view3 = [[CZD_OtherDetailTimeLineView alloc] initWithFrame:CGRectMake(self.view1.nim_left, self.view2.nim_bottom, self.view1.nim_width, self.view1.nim_height)];
        [self.bgView addSubview:self.view3];
        
        self.view4 = [[CZD_OtherDetailTimeLineView alloc] initWithFrame:CGRectMake(self.view1.nim_left, self.view3.nim_bottom, self.view1.nim_width, self.view1.nim_height)];
        [self.bgView addSubview:self.view4];
        
        self.view5 = [[CZD_OtherDetailTimeLineView alloc] initWithFrame:CGRectMake(self.view1.nim_left, self.view4.nim_bottom, self.view1.nim_width, self.view1.nim_height)];
        [self.bgView addSubview:self.view5];
        
        self.view6 = [[CZD_OtherDetailTimeLineView alloc] initWithFrame:CGRectMake(self.view1.nim_left, self.view5.nim_bottom, self.view1.nim_width, self.view1.nim_height)];
        [self.bgView addSubview:self.view6];
        
        self.view7 = [[CZD_OtherDetailTimeLineView alloc] initWithFrame:CGRectMake(self.view1.nim_left, self.view6.nim_bottom, self.view1.nim_width, self.view1.nim_height)];
        [self.bgView addSubview:self.view7];
        
        self.view8 = [[CZD_OtherDetailTimeLineView alloc] initWithFrame:CGRectMake(self.view1.nim_left, self.view7.nim_bottom, self.view1.nim_width, self.view1.nim_height)];
        [self.bgView addSubview:self.view8];
        
        self.view9 = [[CZD_OtherDetailTimeLineView alloc] initWithFrame:CGRectMake(self.view1.nim_left, self.view8.nim_bottom, self.view1.nim_width, self.view1.nim_height)];
        [self.bgView addSubview:self.view9];
        
        self.view10 = [[CZD_OtherDetailTimeLineView alloc] initWithFrame:CGRectMake(self.view1.nim_left, self.view9.nim_bottom, self.view1.nim_width, self.view1.nim_height)];
        [self.bgView addSubview:self.view10];
        
        self.view11 = [[CZD_OtherDetailTimeLineView alloc] initWithFrame:CGRectMake(self.view1.nim_left, self.view10.nim_bottom, self.view1.nim_width, self.view1.nim_height)];
        [self.bgView addSubview:self.view11];
        
        self.view12 = [[CZD_OtherDetailTimeLineView alloc] initWithFrame:CGRectMake(self.view1.nim_left, self.view11.nim_bottom, self.view1.nim_width, self.view1.nim_height)];
        [self.bgView addSubview:self.view12];
    }
    return self;
}

-(void)setModel:(CaoZuoDanMainModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.view1.title = @"新建";
    self.view1.time = self.model.create_time;
    self.view1.isFirst = YES;
    self.view1.isLast = NO;
    if (self.model.status == CaoZuoDanStatusNew) {
        self.view1.isSelected = YES;
    }else {
        self.view1.isSelected = NO;
    }
    
    self.view2.title = @"确认";
    self.view2.time = self.model.confirm_time;
    self.view2.isFirst = NO;
    self.view2.isLast = NO;
    if (self.model.status == CaoZuoDanStatusSure) {
        self.view2.isSelected = YES;
    }else {
        self.view2.isSelected = NO;
    }
    
    self.view3.title = @"交货出发";
    self.view3.time = self.model.deliver_start_time;
    self.view3.isFirst = NO;
    self.view3.isLast = NO;
    if (self.model.status == CaoZuoDanStatusJiaoHuoChuFa) {
        self.view3.isSelected = YES;
    }else {
        self.view3.isSelected = NO;
    }
    
    self.view4.title = @"交货到达";
    self.view4.time = self.model.deliver_arrive_time;
    self.view4.isFirst = NO;
    self.view4.isLast = NO;
    if (self.model.status == CaoZuoDanStatusJiaoHuoDaoDa) {
        self.view4.isSelected = YES;
    }else {
        self.view4.isSelected = NO;
    }
    
    self.view5.title = @"干线签收";
    self.view5.time = self.model.trunkline_sign_time;
    self.view5.isFirst = NO;
    self.view5.isLast = NO;
    if (self.model.status == CaoZuoDanStatusGanXianQianShou) {
        self.view5.isSelected = YES;
    }else {
        self.view5.isSelected = NO;
    }
    
    self.view6.title = @"干线出发";
    self.view6.time = self.model.trunkline_start_time;
    self.view6.isFirst = NO;
    self.view6.isLast = NO;
    if (self.model.status == CaoZuoDanStatusGanXianChuFa) {
        self.view6.isSelected = YES;
    }else {
        self.view6.isSelected = NO;
    }
    
    self.view7.title = @"干线途中";
    self.view7.time = self.model.trunkline_to_time;
    self.view7.isFirst = NO;
    self.view7.isLast = NO;
    if (self.model.status == CaoZuoDanStatusGanXianTuZhong) {
        self.view7.isSelected = YES;
    }else {
        self.view7.isSelected = NO;
    }
    
    self.view8.title = @"干线到达";
    self.view8.time = self.model.trunkline_arrive_time;
    self.view8.isFirst = NO;
    self.view8.isLast = NO;
    if (self.model.status == CaoZuoDanStatusGanXianDaoDa) {
        self.view8.isSelected = YES;
    }else {
        self.view8.isSelected = NO;
    }
    
    self.view9.title = @"派送签收";
    self.view9.time = self.model.send_start_time;
    self.view9.isFirst = NO;
    self.view9.isLast = NO;
    if (self.model.status == CaoZuoDanStatusPaiSongQianShou) {
        self.view9.isSelected = YES;
    }else {
        self.view9.isSelected = NO;
    }
    
    self.view10.title = @"运单签收";
    self.view10.time = self.model.waybill_time;
    self.view10.isFirst = NO;
    self.view10.isLast = NO;
    if (self.model.status == CaoZuoDanStatusYunDanQianShou) {
        self.view10.isSelected = YES;
    }else {
        self.view10.isSelected = NO;
    }
    
    self.view11.title = @"回单返回";
    self.view11.time = self.model.receipt_return_time;
    self.view11.isFirst = NO;
    self.view11.isLast = NO;
    if (self.model.status == CaoZuoDanStatusHuiDanFanHui) {
        self.view11.isSelected = YES;
    }else {
        self.view11.isSelected = NO;
    }
    
    self.view12.title = @"完成";
    self.view12.time = self.model.finish_time;
    self.view12.isFirst = NO;
    self.view12.isLast = YES;
    if (self.model.status == CaoZuoDanStatusFinish) {
        self.view12.isSelected = YES;
    }else {
        self.view12.isSelected = NO;
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

@interface CZD_OtherDetailTimeLineView ()

@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *timeLab;
@property (nonatomic, strong) UILabel *topLine;
@property (nonatomic, strong) UILabel *botLine;
@property (nonatomic, strong) UILabel *midDot;
@property (nonatomic, strong) UIImageView *selectImgView;

@end

@implementation CZD_OtherDetailTimeLineView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 7.5, 75, 15)];
        self.titleLab.textAlignment = NSTextAlignmentCenter;
        self.titleLab.font = [UIFont systemFontOfSize:14];
        self.titleLab.textColor = HexColor(0x9C9DB3);
        [self addSubview:self.titleLab];
        
        self.midDot = [UILabel new];
        self.midDot.nim_width = 10;
        self.midDot.nim_height = 10;
        self.midDot.nim_left = self.titleLab.nim_right + 7;
        self.midDot.nim_centerY = self.titleLab.nim_centerY;
        self.midDot.layer.masksToBounds = YES;
        self.midDot.layer.cornerRadius = 5;
        self.midDot.backgroundColor = HexColor(0x9C9DB3);
        [self addSubview:self.midDot];
        
        self.topLine = [UILabel new];
        self.topLine.backgroundColor = HexColor(0x9C9DB3);
        self.topLine.nim_top = 0;
        self.topLine.nim_width = 2;
        self.topLine.nim_centerX = self.midDot.nim_centerX;
        self.topLine.nim_height = self.midDot.nim_top - 2;
        [self addSubview:self.topLine];
        
        self.botLine = [UILabel new];
        self.botLine.backgroundColor = HexColor(0x9C9DB3);
        self.botLine.nim_top = self.midDot.nim_bottom + 2;
        self.botLine.nim_width = 2;
        self.botLine.nim_centerX = self.midDot.nim_centerX;
        self.botLine.nim_height = frame.size.height - self.botLine.nim_top;
        [self addSubview:self.botLine];
        
        self.timeLab = [[UILabel alloc] initWithFrame:CGRectMake(20 + self.midDot.nim_right, 7.5, frame.size.width - (20 + self.midDot.nim_right), 15)];
        self.timeLab.textAlignment = NSTextAlignmentLeft;
        self.timeLab.font = [UIFont systemFontOfSize:14];
        self.timeLab.textColor = HexColor(0x9C9DB3);
        [self addSubview:self.timeLab];
        
        self.selectImgView = [UIImageView new];
        self.selectImgView.nim_width = 24;
        self.selectImgView.nim_height = 24;
        self.selectImgView.nim_centerX = self.midDot.nim_centerX;
        self.selectImgView.nim_centerY = self.midDot.nim_centerY;
        self.selectImgView.image = [UIImage imageNamed:@"icon_map_car_status_selected"];
        self.selectImgView.hidden = YES;
        [self addSubview:self.selectImgView];
    }
    return self;
}

-(void)setTitle:(NSString *)title {
    _title = title;
    self.titleLab.text = title;
}

-(void)setTime:(NSString *)time {
    _time = time;
    self.timeLab.text = time;
}

-(void)setIsFirst:(BOOL)isFirst {
    _isFirst = isFirst;
    self.topLine.hidden = isFirst;
}

-(void)setIsLast:(BOOL)isLast {
    _isLast = isLast;
    self.botLine.hidden = isLast;
}

-(void)setIsSelected:(BOOL)isSelected {
    _isSelected = isSelected;
    self.selectImgView.hidden = !isSelected;
    if (isSelected) {
        self.titleLab.nim_height = 19;
        self.titleLab.nim_centerY = self.selectImgView.nim_centerY;
        self.titleLab.font = BoldFontOfSize(18);
        self.titleLab.textColor = HexColor(0x3D68EB);
        
        self.timeLab.nim_height = 19;
        self.timeLab.nim_centerY = self.selectImgView.nim_centerY;
        self.timeLab.font = BoldFontOfSize(18);
        self.timeLab.textColor = HexColor(0x2B2C44);
    }else {
        self.titleLab.nim_height = 15;
        self.titleLab.nim_centerY = self.midDot.nim_centerY;
        self.titleLab.font = [UIFont systemFontOfSize:14];
        self.titleLab.textColor = HexColor(0x9C9DB3);
        
        self.timeLab.nim_height = 15;
        self.timeLab.nim_centerY = self.midDot.nim_centerY;
        self.timeLab.font = [UIFont systemFontOfSize:14];
        self.timeLab.textColor = HexColor(0x9C9DB3);
    }
}

@end
